<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>全局 API | Vue.js</title>
    <meta name="generator" content="VuePress 1.5.4">
    <link href="https://fonts.googleapis.com/css?family=Inter:300,400,500,600|Open+Sans:400,600;display=swap" rel="stylesheet">
    <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link rel="icon" href="/logo.png">
    <script src="https://player.youku.com/iframeapi"></script>
    <meta name="description" content="Vue.js - The Progressive JavaScript Framework">
    <link rel="preload" href="/assets/css/0.styles.60414370.css" as="style"><link rel="preload" href="/assets/js/app.0a9bf1a0.js" as="script"><link rel="preload" href="/assets/js/9.f307b0a5.js" as="script"><link rel="preload" href="/assets/js/18.9c9769d1.js" as="script"><link rel="preload" href="/assets/js/10.523605bb.js" as="script"><link rel="preload" href="/assets/js/42.eb469d2e.js" as="script"><link rel="prefetch" href="/assets/js/1.832c44bf.js"><link rel="prefetch" href="/assets/js/100.6c7a3206.js"><link rel="prefetch" href="/assets/js/101.656addb5.js"><link rel="prefetch" href="/assets/js/102.fddd4c59.js"><link rel="prefetch" href="/assets/js/103.8b570fcc.js"><link rel="prefetch" href="/assets/js/104.b1a5605a.js"><link rel="prefetch" href="/assets/js/105.edde2e45.js"><link rel="prefetch" href="/assets/js/106.3b04c318.js"><link rel="prefetch" href="/assets/js/107.98cab24c.js"><link rel="prefetch" href="/assets/js/108.15d2ab25.js"><link rel="prefetch" href="/assets/js/109.5f483cd0.js"><link rel="prefetch" href="/assets/js/11.43202c8c.js"><link rel="prefetch" href="/assets/js/110.de44b32c.js"><link rel="prefetch" href="/assets/js/111.e247818d.js"><link rel="prefetch" href="/assets/js/112.f330b33d.js"><link rel="prefetch" href="/assets/js/113.d26db724.js"><link rel="prefetch" href="/assets/js/114.4a085227.js"><link rel="prefetch" href="/assets/js/115.6f41e46c.js"><link rel="prefetch" href="/assets/js/116.d9f31fc2.js"><link rel="prefetch" href="/assets/js/117.6bc037ec.js"><link rel="prefetch" href="/assets/js/118.b6d13098.js"><link rel="prefetch" href="/assets/js/119.40081175.js"><link rel="prefetch" href="/assets/js/12.9ac43f9f.js"><link rel="prefetch" href="/assets/js/120.dc59e2a2.js"><link rel="prefetch" href="/assets/js/121.5d6c245d.js"><link rel="prefetch" href="/assets/js/122.44eb5e5a.js"><link rel="prefetch" href="/assets/js/123.2fbebc5c.js"><link rel="prefetch" href="/assets/js/124.9733dae9.js"><link rel="prefetch" href="/assets/js/125.35fe073b.js"><link rel="prefetch" href="/assets/js/126.b2d1ea91.js"><link rel="prefetch" href="/assets/js/127.3d7f3105.js"><link rel="prefetch" href="/assets/js/128.aa600ea3.js"><link rel="prefetch" href="/assets/js/129.92b123b0.js"><link rel="prefetch" href="/assets/js/13.61cfe0ac.js"><link rel="prefetch" href="/assets/js/130.65930d6d.js"><link rel="prefetch" href="/assets/js/131.fe452d41.js"><link rel="prefetch" href="/assets/js/132.8db41894.js"><link rel="prefetch" href="/assets/js/133.2422a318.js"><link rel="prefetch" href="/assets/js/134.28ae1eb3.js"><link rel="prefetch" href="/assets/js/135.854307ee.js"><link rel="prefetch" href="/assets/js/136.42e4e007.js"><link rel="prefetch" href="/assets/js/137.c557b795.js"><link rel="prefetch" href="/assets/js/138.8314e9f0.js"><link rel="prefetch" href="/assets/js/139.4a91ed8c.js"><link rel="prefetch" href="/assets/js/14.c6ae250c.js"><link rel="prefetch" href="/assets/js/140.5be2f667.js"><link rel="prefetch" href="/assets/js/141.02fbd174.js"><link rel="prefetch" href="/assets/js/142.f1c4e87e.js"><link rel="prefetch" href="/assets/js/143.59791aa7.js"><link rel="prefetch" href="/assets/js/144.fb6601d0.js"><link rel="prefetch" href="/assets/js/145.11777ee6.js"><link rel="prefetch" href="/assets/js/15.99a67fb3.js"><link rel="prefetch" href="/assets/js/16.54274551.js"><link rel="prefetch" href="/assets/js/17.620b927c.js"><link rel="prefetch" href="/assets/js/19.3a6eb738.js"><link rel="prefetch" href="/assets/js/2.10e2fb64.js"><link rel="prefetch" href="/assets/js/20.4f240fd5.js"><link rel="prefetch" href="/assets/js/21.b5c24ec0.js"><link rel="prefetch" href="/assets/js/22.6b36d53a.js"><link rel="prefetch" href="/assets/js/23.0742dc98.js"><link rel="prefetch" href="/assets/js/24.490994ab.js"><link rel="prefetch" href="/assets/js/25.854225c9.js"><link rel="prefetch" href="/assets/js/26.cb8bede1.js"><link rel="prefetch" href="/assets/js/27.01fe0de5.js"><link rel="prefetch" href="/assets/js/28.8d33f619.js"><link rel="prefetch" href="/assets/js/29.1005b103.js"><link rel="prefetch" href="/assets/js/3.4ba5caef.js"><link rel="prefetch" href="/assets/js/30.0629b722.js"><link rel="prefetch" href="/assets/js/31.41c2c5b0.js"><link rel="prefetch" href="/assets/js/32.7709b53d.js"><link rel="prefetch" href="/assets/js/33.7e973829.js"><link rel="prefetch" href="/assets/js/34.107475bf.js"><link rel="prefetch" href="/assets/js/35.e83bdd9b.js"><link rel="prefetch" href="/assets/js/36.e0922c67.js"><link rel="prefetch" href="/assets/js/37.af806c96.js"><link rel="prefetch" href="/assets/js/38.94bae313.js"><link rel="prefetch" href="/assets/js/39.f15cd956.js"><link rel="prefetch" href="/assets/js/4.b65b2ec4.js"><link rel="prefetch" href="/assets/js/40.18818521.js"><link rel="prefetch" href="/assets/js/41.cc39555d.js"><link rel="prefetch" href="/assets/js/43.7bdc7f53.js"><link rel="prefetch" href="/assets/js/44.c15154a9.js"><link rel="prefetch" href="/assets/js/45.e28b1e26.js"><link rel="prefetch" href="/assets/js/46.1a582225.js"><link rel="prefetch" href="/assets/js/47.1681e4e7.js"><link rel="prefetch" href="/assets/js/48.c7e4df2a.js"><link rel="prefetch" href="/assets/js/49.24a40e32.js"><link rel="prefetch" href="/assets/js/5.436c63ff.js"><link rel="prefetch" href="/assets/js/50.79ca1e35.js"><link rel="prefetch" href="/assets/js/51.4d6124d9.js"><link rel="prefetch" href="/assets/js/52.93b75fa3.js"><link rel="prefetch" href="/assets/js/53.99ab0219.js"><link rel="prefetch" href="/assets/js/54.91605e00.js"><link rel="prefetch" href="/assets/js/55.d1fdbf6f.js"><link rel="prefetch" href="/assets/js/56.e162390f.js"><link rel="prefetch" href="/assets/js/57.af6ab199.js"><link rel="prefetch" href="/assets/js/58.71eff2a5.js"><link rel="prefetch" href="/assets/js/59.b70c19c9.js"><link rel="prefetch" href="/assets/js/6.1bc8dee2.js"><link rel="prefetch" href="/assets/js/60.03187705.js"><link rel="prefetch" href="/assets/js/61.c9596d10.js"><link rel="prefetch" href="/assets/js/62.28b9a2e8.js"><link rel="prefetch" href="/assets/js/63.a5f17acf.js"><link rel="prefetch" href="/assets/js/64.deca5d49.js"><link rel="prefetch" href="/assets/js/65.8014765f.js"><link rel="prefetch" href="/assets/js/66.c136f2b4.js"><link rel="prefetch" href="/assets/js/67.55b8c4d6.js"><link rel="prefetch" href="/assets/js/68.ff568b2f.js"><link rel="prefetch" href="/assets/js/69.cbb0de95.js"><link rel="prefetch" href="/assets/js/70.9a450c62.js"><link rel="prefetch" href="/assets/js/71.56ddc8d7.js"><link rel="prefetch" href="/assets/js/72.ff8c82c4.js"><link rel="prefetch" href="/assets/js/73.5a3ae71c.js"><link rel="prefetch" href="/assets/js/74.d43f66e7.js"><link rel="prefetch" href="/assets/js/75.a0490d28.js"><link rel="prefetch" href="/assets/js/76.51277fc3.js"><link rel="prefetch" href="/assets/js/77.12725190.js"><link rel="prefetch" href="/assets/js/78.e3426443.js"><link rel="prefetch" href="/assets/js/79.34f80eb5.js"><link rel="prefetch" href="/assets/js/80.e7d07c97.js"><link rel="prefetch" href="/assets/js/81.497c1c98.js"><link rel="prefetch" href="/assets/js/82.5edfa1e6.js"><link rel="prefetch" href="/assets/js/83.72c9f367.js"><link rel="prefetch" href="/assets/js/84.72494822.js"><link rel="prefetch" href="/assets/js/85.02c708f2.js"><link rel="prefetch" href="/assets/js/86.75fdd91f.js"><link rel="prefetch" href="/assets/js/87.431ab614.js"><link rel="prefetch" href="/assets/js/88.06c97259.js"><link rel="prefetch" href="/assets/js/89.1c6506f7.js"><link rel="prefetch" href="/assets/js/90.7f074177.js"><link rel="prefetch" href="/assets/js/91.82276ba6.js"><link rel="prefetch" href="/assets/js/92.2d5fa7b8.js"><link rel="prefetch" href="/assets/js/93.9ae1367c.js"><link rel="prefetch" href="/assets/js/94.3ba6340b.js"><link rel="prefetch" href="/assets/js/95.e31bf445.js"><link rel="prefetch" href="/assets/js/96.b6f4c3e4.js"><link rel="prefetch" href="/assets/js/97.fd612974.js"><link rel="prefetch" href="/assets/js/98.fc2e9816.js"><link rel="prefetch" href="/assets/js/99.ea1b3d86.js"><link rel="prefetch" href="/assets/js/vendors~docsearch.a100821a.js">
    <link rel="stylesheet" href="/assets/css/0.styles.60414370.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><!----> <header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/logo.png" alt="Vue.js" class="logo"> <span class="site-name can-hide">Vue.js</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="文档菜单" class="dropdown-title"><span class="title">文档</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/guide/introduction.html" class="nav-link">
  教程
</a></li><li class="dropdown-item"><!----> <a href="/guide/migration/introduction.html" class="nav-link">
  v3 迁移指南
</a></li><li class="dropdown-item"><!----> <a href="/style-guide/" class="nav-link">
  风格指南
</a></li><li class="dropdown-item"><!----> <a href="/cookbook/" class="nav-link">
  Cookbook
</a></li><li class="dropdown-item"><!----> <a href="/examples/markdown.html" class="nav-link">
  示例
</a></li></ul></div></div><div class="nav-item"><a href="/api/application-config.html" class="nav-link">
  API Reference
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="生态系统" class="dropdown-title"><span class="title">生态系统</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          社区
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/community/team/" class="nav-link">
  团队
</a></li><li class="dropdown-subitem"><a href="/community/partners.html" class="nav-link">
  合作伙伴
</a></li><li class="dropdown-subitem"><a href="/community/join/" class="nav-link">
  加入
</a></li><li class="dropdown-subitem"><a href="/community/themes/" class="nav-link">
  主题
</a></li></ul></li><li class="dropdown-item"><h4>
          官方项目
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://next.router.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue Router
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-subitem"><a href="https://vuex.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vuex
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-subitem"><a href="https://cli.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue CLI
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-subitem"><a href="https://vuejs.github.io/vue-test-utils-next-docs/guide/introduction.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue Test Utils
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-subitem"><a href="https://github.com/vuejs/vue-devtools" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Devtools
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-subitem"><a href="https://news.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Weekly news
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="支持 Vue" class="dropdown-title"><span class="title">支持 Vue</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/support-vuejs/#one-time-donations" class="nav-link">
  一次性捐款
</a></li><li class="dropdown-item"><!----> <a href="/support-vuejs/#recurring-pledges" class="nav-link">
  周期性捐款
</a></li><li class="dropdown-item"><!----> <a href="https://www.smallsticker.com/%E8%B4%B4%E7%BA%B8/vue.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  贴纸
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://osholic.com/?utm_source=vue&amp;utm_medium=dropdown" target="_blank" rel="noopener noreferrer" class="nav-link external">
  周边
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://vue.threadless.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  T-Shirt 商店
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="多语言" class="dropdown-title"><span class="title">多语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://v3.vuejs.org" target="_blank" rel="noopener noreferrer" class="nav-link external">
  English
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div> <a href="https://github.com/vuejs/docs-next-zh-cn" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav> <!----></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="文档菜单" class="dropdown-title"><span class="title">文档</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/guide/introduction.html" class="nav-link">
  教程
</a></li><li class="dropdown-item"><!----> <a href="/guide/migration/introduction.html" class="nav-link">
  v3 迁移指南
</a></li><li class="dropdown-item"><!----> <a href="/style-guide/" class="nav-link">
  风格指南
</a></li><li class="dropdown-item"><!----> <a href="/cookbook/" class="nav-link">
  Cookbook
</a></li><li class="dropdown-item"><!----> <a href="/examples/markdown.html" class="nav-link">
  示例
</a></li></ul></div></div><div class="nav-item"><a href="/api/application-config.html" class="nav-link">
  API Reference
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="生态系统" class="dropdown-title"><span class="title">生态系统</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          社区
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/community/team/" class="nav-link">
  团队
</a></li><li class="dropdown-subitem"><a href="/community/partners.html" class="nav-link">
  合作伙伴
</a></li><li class="dropdown-subitem"><a href="/community/join/" class="nav-link">
  加入
</a></li><li class="dropdown-subitem"><a href="/community/themes/" class="nav-link">
  主题
</a></li></ul></li><li class="dropdown-item"><h4>
          官方项目
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="https://next.router.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue Router
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-subitem"><a href="https://vuex.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vuex
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-subitem"><a href="https://cli.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue CLI
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-subitem"><a href="https://vuejs.github.io/vue-test-utils-next-docs/guide/introduction.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Vue Test Utils
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-subitem"><a href="https://github.com/vuejs/vue-devtools" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Devtools
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-subitem"><a href="https://news.vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Weekly news
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="支持 Vue" class="dropdown-title"><span class="title">支持 Vue</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/support-vuejs/#one-time-donations" class="nav-link">
  一次性捐款
</a></li><li class="dropdown-item"><!----> <a href="/support-vuejs/#recurring-pledges" class="nav-link">
  周期性捐款
</a></li><li class="dropdown-item"><!----> <a href="https://www.smallsticker.com/%E8%B4%B4%E7%BA%B8/vue.html" target="_blank" rel="noopener noreferrer" class="nav-link external">
  贴纸
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://osholic.com/?utm_source=vue&amp;utm_medium=dropdown" target="_blank" rel="noopener noreferrer" class="nav-link external">
  周边
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="https://vue.threadless.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  T-Shirt 商店
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="多语言" class="dropdown-title"><span class="title">多语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://v3.vuejs.org" target="_blank" rel="noopener noreferrer" class="nav-link external">
  English
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div> <a href="https://github.com/vuejs/docs-next-zh-cn" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav>  <ul class="sidebar-links"><li><a href="/api/application-config.html" class="sidebar-link">应用配置</a></li><li><a href="/api/application-api.html" class="sidebar-link">应用 API</a></li><li><a href="/api/global-api.html" aria-current="page" class="active sidebar-link">全局 API</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/api/global-api.html#createapp" class="sidebar-link">createApp</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/api/global-api.html#参数" class="sidebar-link">参数</a></li><li class="sidebar-sub-header"><a href="/api/global-api.html#类型声明" class="sidebar-link">类型声明</a></li></ul></li><li class="sidebar-sub-header"><a href="/api/global-api.html#h" class="sidebar-link">h</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/api/global-api.html#参数-2" class="sidebar-link">参数</a></li></ul></li><li class="sidebar-sub-header"><a href="/api/global-api.html#definecomponent" class="sidebar-link">defineComponent</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/api/global-api.html#参数-3" class="sidebar-link">参数</a></li></ul></li><li class="sidebar-sub-header"><a href="/api/global-api.html#defineasynccomponent" class="sidebar-link">defineAsyncComponent</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/api/global-api.html#参数-4" class="sidebar-link">参数</a></li></ul></li><li class="sidebar-sub-header"><a href="/api/global-api.html#resolvecomponent" class="sidebar-link">resolveComponent</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/api/global-api.html#参数-5" class="sidebar-link">参数</a></li></ul></li><li class="sidebar-sub-header"><a href="/api/global-api.html#resolvedynamiccomponent" class="sidebar-link">resolveDynamicComponent</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/api/global-api.html#参数-6" class="sidebar-link">参数</a></li></ul></li><li class="sidebar-sub-header"><a href="/api/global-api.html#resolvedirective" class="sidebar-link">resolveDirective</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/api/global-api.html#参数-7" class="sidebar-link">参数</a></li></ul></li><li class="sidebar-sub-header"><a href="/api/global-api.html#withdirectives" class="sidebar-link">withDirectives</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/api/global-api.html#参数-8" class="sidebar-link">参数</a></li></ul></li><li class="sidebar-sub-header"><a href="/api/global-api.html#createrenderer" class="sidebar-link">createRenderer</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/api/global-api.html#参数-9" class="sidebar-link">参数</a></li></ul></li><li class="sidebar-sub-header"><a href="/api/global-api.html#nexttick" class="sidebar-link">nextTick</a></li></ul></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>选项</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/api/options-data.html" class="sidebar-link">Data</a></li><li><a href="/api/options-dom.html" class="sidebar-link">DOM</a></li><li><a href="/api/options-lifecycle-hooks.html" class="sidebar-link">生命周期钩子</a></li><li><a href="/api/options-assets.html" class="sidebar-link">选项/Assets</a></li><li><a href="/api/options-composition.html" class="sidebar-link">组合</a></li><li><a href="/api/options-misc.html" class="sidebar-link">其他</a></li></ul></section></li><li><a href="/api/instance-properties.html" class="sidebar-link">实例 property</a></li><li><a href="/api/instance-methods.html" class="sidebar-link">实例方法</a></li><li><a href="/api/directives.html" class="sidebar-link">指令</a></li><li><a href="/api/special-attributes.html" class="sidebar-link">特殊指令</a></li><li><a href="/api/built-in-components.html" class="sidebar-link">内置组件</a></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>响应性 API</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/api/basic-reactivity.html" class="sidebar-link">响应性基础 API</a></li><li><a href="/api/refs-api.html" class="sidebar-link">Refs</a></li><li><a href="/api/computed-watch-api.html" class="sidebar-link">Computed 与 watch</a></li></ul></section></li><li><a href="/api/composition-api.html" class="sidebar-link">组合 API</a></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="全局-api"><a href="#全局-api" class="header-anchor">#</a> 全局 API</h1> <h2 id="createapp"><a href="#createapp" class="header-anchor">#</a> createApp</h2> <p>返回一个提供应用上下文的应用实例。应用实例挂载的整个组件树共享同一个上下文。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> app <span class="token operator">=</span> Vue<span class="token punctuation">.</span><span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>你可以在 <code>createApp</code> 之后链式调用其它方法，这些方法可以在<a href="/api/application-api.html">应用 API</a> 中找到。</p> <h3 id="参数"><a href="#参数" class="header-anchor">#</a> 参数</h3> <p>该函数接收一个根组件选项对象作为第一个参数：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> app <span class="token operator">=</span> Vue<span class="token punctuation">.</span><span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token function">data</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">{</span>
      <span class="token operator">...</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  methods<span class="token operator">:</span> <span class="token punctuation">{</span><span class="token operator">...</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  computed<span class="token operator">:</span> <span class="token punctuation">{</span><span class="token operator">...</span><span class="token punctuation">}</span>
  <span class="token operator">...</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p>使用第二个参数，我们可以将根 prop 传递给应用程序：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> app <span class="token operator">=</span> Vue<span class="token punctuation">.</span><span class="token function">createApp</span><span class="token punctuation">(</span>
  <span class="token punctuation">{</span>
    props<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">'username'</span><span class="token punctuation">]</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">{</span> username<span class="token operator">:</span> <span class="token string">'Evan'</span> <span class="token punctuation">}</span>
<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>app<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token comment">&lt;!-- 会显示 'Evan' --&gt;</span>
  {{ username }}
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="类型声明"><a href="#类型声明" class="header-anchor">#</a> 类型声明</h3> <div class="language-ts line-numbers-mode"><pre class="language-ts"><code><span class="token keyword">interface</span> <span class="token class-name">Data</span> <span class="token punctuation">{</span>
  <span class="token punctuation">[</span>key<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">]</span><span class="token operator">:</span> <span class="token builtin">unknown</span>
<span class="token punctuation">}</span>

<span class="token keyword">export</span> <span class="token keyword">type</span> <span class="token class-name">CreateAppFunction<span class="token operator">&lt;</span>HostElement<span class="token operator">&gt;</span></span> <span class="token operator">=</span> <span class="token punctuation">(</span>
  rootComponent<span class="token operator">:</span> PublicAPIComponent<span class="token punctuation">,</span>
  rootProps<span class="token operator">?</span><span class="token operator">:</span> Data <span class="token operator">|</span> <span class="token keyword">null</span>
<span class="token punctuation">)</span> <span class="token operator">=&gt;</span> App<span class="token operator">&lt;</span>HostElement<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="h"><a href="#h" class="header-anchor">#</a> h</h2> <p>返回一个”虚拟节点“，通常缩写为 <strong>VNode</strong>：一个普通对象，其中包含向 Vue 描述它应在页面上渲染哪种节点的信息，包括所有子节点的描述。它的目的是用于手动编写的<a href="/guide/render-function.html">渲染函数</a>：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> Vue<span class="token punctuation">.</span><span class="token function">h</span><span class="token punctuation">(</span><span class="token string">'h1'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token string">'Some title'</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="参数-2"><a href="#参数-2" class="header-anchor">#</a> 参数</h3> <p>接收三个参数：<code>type</code>，<code>props</code> 和 <code>children</code></p> <h4 id="type"><a href="#type" class="header-anchor">#</a> type</h4> <ul><li><p><strong>类型：</strong><code>String | Object | Function</code></p></li> <li><p><strong>详细：</strong></p> <p>HTML 标签名、组件或异步组件。使用返回 null 的函数将渲染一个注释。此参数是必需的。</p></li></ul> <h4 id="props"><a href="#props" class="header-anchor">#</a> props</h4> <ul><li><p><strong>类型：</strong><code>Object</code></p></li> <li><p><strong>详细：</strong></p> <p>一个对象，与我们将在模板中使用的 attribute、prop 和事件相对应。可选。</p></li></ul> <h4 id="children"><a href="#children" class="header-anchor">#</a> children</h4> <ul><li><p><strong>类型：</strong><code>String | Array | Object</code></p></li> <li><p><strong>详细：</strong></p> <p>子代 VNode，使用 <code>h()</code> 生成，或者使用字符串来获取“文本 VNode”，或带有插槽的对象。可选。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token function">h</span><span class="token punctuation">(</span><span class="token string">'div'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>
  <span class="token string">'Some text comes first.'</span><span class="token punctuation">,</span>
  <span class="token function">h</span><span class="token punctuation">(</span><span class="token string">'h1'</span><span class="token punctuation">,</span> <span class="token string">'A headline'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token function">h</span><span class="token punctuation">(</span>MyComponent<span class="token punctuation">,</span> <span class="token punctuation">{</span>
    someProp<span class="token operator">:</span> <span class="token string">'foobar'</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div></li></ul> <h2 id="definecomponent"><a href="#definecomponent" class="header-anchor">#</a> defineComponent</h2> <p>从实现上看，<code>defineComponent</code> 只返回传递给它的对象。但是，就类型而言，返回的值有一个合成类型的构造函数，用于手动渲染函数、TSX 和 IDE 工具支持。</p> <h3 id="参数-3"><a href="#参数-3" class="header-anchor">#</a> 参数</h3> <p>具有组件选项的对象</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> defineComponent <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>

<span class="token keyword">const</span> MyComponent <span class="token operator">=</span> <span class="token function">defineComponent</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token function">data</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">{</span> count<span class="token operator">:</span> <span class="token number">1</span> <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  methods<span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token function">increment</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span>count<span class="token operator">++</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="defineasynccomponent"><a href="#defineasynccomponent" class="header-anchor">#</a> defineAsyncComponent</h2> <p>创建一个只有在需要时才会加载的异步组件。</p> <h3 id="参数-4"><a href="#参数-4" class="header-anchor">#</a> 参数</h3> <p>对于基本用法，<code>defineAsyncComponent</code> 可以接受一个返回 <code>Promise</code> 的工厂函数。Promise 的 <code>resolve</code> 回调应该在服务端返回组件定义后被调用。你也可以调用 <code>reject(reason)</code> 来表示加载失败。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> defineAsyncComponent <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>

<span class="token keyword">const</span> AsyncComp <span class="token operator">=</span> <span class="token function">defineAsyncComponent</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span>
  <span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">'./components/AsyncComponent.vue'</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span>

app<span class="token punctuation">.</span><span class="token function">component</span><span class="token punctuation">(</span><span class="token string">'async-component'</span><span class="token punctuation">,</span> AsyncComp<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>当使用<a href="/guide/component-registration.html#local-registration">局部注册</a>时，你也可以直接提供一个返回 <code>Promise</code> 的函数：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> createApp<span class="token punctuation">,</span> defineAsyncComponent <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>

<span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token comment">// ...</span>
  components<span class="token operator">:</span> <span class="token punctuation">{</span>
    AsyncComponent<span class="token operator">:</span> <span class="token function">defineAsyncComponent</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span>
      <span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">'./components/AsyncComponent.vue'</span><span class="token punctuation">)</span>
    <span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p>对于高阶用法，<code>defineAsyncComponent</code> 可以接受一个对象：</p> <p><code>defineAsyncComponent</code> 方法还可以返回以下格式的对象：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> defineAsyncComponent <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>

<span class="token keyword">const</span> AsyncComp <span class="token operator">=</span> <span class="token function">defineAsyncComponent</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token comment">// 工厂函数</span>
  <span class="token function-variable function">loader</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">'./Foo.vue'</span><span class="token punctuation">)</span>
  <span class="token comment">// 加载异步组件时要使用的组件</span>
  loadingComponent<span class="token operator">:</span> LoadingComponent<span class="token punctuation">,</span>
  <span class="token comment">// 加载失败时要使用的组件</span>
  errorComponent<span class="token operator">:</span> ErrorComponent<span class="token punctuation">,</span>
  <span class="token comment">// 在显示 loadingComponent 之前的延迟 | 默认值：200（单位 ms）</span>
  delay<span class="token operator">:</span> <span class="token number">200</span><span class="token punctuation">,</span>
  <span class="token comment">// 如果提供了 timeout ，并且加载组件的时间超过了设定值，将显示错误组件</span>
  <span class="token comment">// 默认值：Infinity（即永不超时，单位 ms）</span>
  timeout<span class="token operator">:</span> <span class="token number">3000</span><span class="token punctuation">,</span>
  <span class="token comment">// 一个函数，返回一个布尔值，指示当加载程序promise拒绝时异步组件是否应重试</span>
  <span class="token function-variable function">retryWhen</span><span class="token operator">:</span> <span class="token parameter">error</span> <span class="token operator">=&gt;</span> error<span class="token punctuation">.</span>code <span class="token operator">!==</span> <span class="token number">404</span><span class="token punctuation">,</span>
  <span class="token comment">// 允许的最大重试次数</span>
  maxRetries<span class="token operator">:</span> <span class="token number">3</span><span class="token punctuation">,</span>
  <span class="token comment">// 定义组件是否可挂起 | 默认值：true</span>
  suspensible<span class="token operator">:</span> <span class="token boolean">false</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><p><strong>参考</strong>：<a href="/guide/component-dynamic-async.html">动态和异步组件</a></p> <h2 id="resolvecomponent"><a href="#resolvecomponent" class="header-anchor">#</a> resolveComponent</h2> <div class="custom-block warning"><p class="custom-block-title">WARNING</p> <p><code>resolveComponent</code> 只能在 <code>render</code> 或 <code>setup</code> 函数中使用。</p></div> <p>如果在当前应用实例中可用，则允许按名称解析 <code>component</code>。</p> <p>返回一个 <code>Component</code>。如果没有找到，则返回 <code>undefined</code>。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> app <span class="token operator">=</span> Vue<span class="token punctuation">.</span><span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
app<span class="token punctuation">.</span><span class="token function">component</span><span class="token punctuation">(</span><span class="token string">'MyComponent'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
  <span class="token comment">/* ... */</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> resolveComponent <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>
<span class="token function">render</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> MyComponent <span class="token operator">=</span> <span class="token function">resolveComponent</span><span class="token punctuation">(</span><span class="token string">'MyComponent'</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="参数-5"><a href="#参数-5" class="header-anchor">#</a> 参数</h3> <p>接受一个参数：<code>component</code></p> <h4 id="component"><a href="#component" class="header-anchor">#</a> component</h4> <ul><li><p><strong>类型：</strong><code>String</code></p></li> <li><p><strong>详细：</strong></p> <p>已加载的组件的名称。</p></li></ul> <h2 id="resolvedynamiccomponent"><a href="#resolvedynamiccomponent" class="header-anchor">#</a> resolveDynamicComponent</h2> <div class="custom-block warning"><p class="custom-block-title">WARNING</p> <p><code>resolveDynamicComponent</code> 只能在 <code>render</code> 或 <code>setup</code> 函数中使用。</p></div> <p>允许使用与 <code>&lt;component :is=&quot;&quot;&gt;</code> 相同的机制来解析一个 <code>component</code>。</p> <p>返回已解析的 <code>Component</code> 或新创建的 <code>VNode</code>，其中组件名称作为节点标签。如果找不到 <code>Component</code>，将发出警告。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> resolveDynamicComponent <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>
<span class="token function">render</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> MyComponent <span class="token operator">=</span> <span class="token function">resolveDynamicComponent</span><span class="token punctuation">(</span><span class="token string">'MyComponent'</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="参数-6"><a href="#参数-6" class="header-anchor">#</a> 参数</h3> <p>接受一个参数：<code>component</code></p> <h4 id="component-2"><a href="#component-2" class="header-anchor">#</a> component</h4> <ul><li><p><strong>类型：</strong><code>String | Object (组件的选项对象)</code></p></li> <li><p><strong>详细：</strong></p> <p>有关详细信息，请参阅<a href="/guide/component-dynamic-async.html">动态组件</a>上的文档。</p></li></ul> <h2 id="resolvedirective"><a href="#resolvedirective" class="header-anchor">#</a> resolveDirective</h2> <div class="custom-block warning"><p class="custom-block-title">WARNING</p> <p><code>resolveDirective</code> 只能在 <code>render</code> 或 <code>setup</code> 函数中使用。</p></div> <p>如果在当前应用实例中可用，则允许通过其名称解析一个 <code>directive</code>。</p> <p>返回一个 <code>Directive</code>。如果没有找到，则返回 <code>undefined</code>。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> app <span class="token operator">=</span> Vue<span class="token punctuation">.</span><span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
app<span class="token punctuation">.</span><span class="token function">directive</span><span class="token punctuation">(</span><span class="token string">'highlight'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> resolveDirective <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>
<span class="token function">render</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> highlightDirective <span class="token operator">=</span> <span class="token function">resolveDirective</span><span class="token punctuation">(</span><span class="token string">'highlight'</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="参数-7"><a href="#参数-7" class="header-anchor">#</a> 参数</h3> <p>接受一个参数：<code>name</code></p> <h4 id="name"><a href="#name" class="header-anchor">#</a> name</h4> <ul><li><p><strong>类型：</strong><code>String</code></p></li> <li><p><strong>详细：</strong></p> <p>已加载的指令的名称。</p></li></ul> <h2 id="withdirectives"><a href="#withdirectives" class="header-anchor">#</a> withDirectives</h2> <div class="custom-block warning"><p class="custom-block-title">WARNING</p> <p><code>withDirectives</code> 只能在 <code>render</code> 或 <code>setup</code> 函数中使用。</p></div> <p>允许将指令应用于 <strong>VNode</strong>。返回一个包含应用指令的 VNode。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> withDirectives<span class="token punctuation">,</span> resolveDirective <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>
<span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token function">resolveDirective</span><span class="token punctuation">(</span><span class="token string">'foo'</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> bar <span class="token operator">=</span> <span class="token function">resolveDirective</span><span class="token punctuation">(</span><span class="token string">'bar'</span><span class="token punctuation">)</span>

<span class="token keyword">return</span> <span class="token function">withDirectives</span><span class="token punctuation">(</span><span class="token function">h</span><span class="token punctuation">(</span><span class="token string">'div'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>
  <span class="token punctuation">[</span>foo<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>x<span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token punctuation">[</span>bar<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>y<span class="token punctuation">]</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h3 id="参数-8"><a href="#参数-8" class="header-anchor">#</a> 参数</h3> <p>接受两个参数：<code>vnode</code> 和 <code>directives</code>。</p> <h4 id="vnode"><a href="#vnode" class="header-anchor">#</a> vnode</h4> <ul><li><p><strong>类型：</strong><code>vnode</code></p></li> <li><p><strong>详细：</strong></p> <p>一个虚拟节点，通常使用 <code>h()</code> 创建。</p></li></ul> <h4 id="directives"><a href="#directives" class="header-anchor">#</a> directives</h4> <ul><li><p><strong>类型：</strong><code>Array</code></p></li> <li><p><strong>详细：</strong></p> <p>一个指令数组。</p> <p>每个指令本身都是一个数组，最多可以定义 4 个索引，如以下示例所示。</p> <ul><li><code>[directive]</code> - 该指令本身。必选。</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> MyDirective <span class="token operator">=</span> <span class="token function">resolveDirective</span><span class="token punctuation">(</span><span class="token string">'MyDirective'</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> nodeWithDirectives <span class="token operator">=</span> <span class="token function">withDirectives</span><span class="token punctuation">(</span><span class="token function">h</span><span class="token punctuation">(</span><span class="token string">'div'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>MyDirective<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li><code>[directive, value]</code> - 上述内容，再加上分配给指令的类型为 <code>any</code> 的值。</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> MyDirective <span class="token operator">=</span> <span class="token function">resolveDirective</span><span class="token punctuation">(</span><span class="token string">'MyDirective'</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> nodeWithDirectives <span class="token operator">=</span> <span class="token function">withDirectives</span><span class="token punctuation">(</span><span class="token function">h</span><span class="token punctuation">(</span><span class="token string">'div'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>MyDirective<span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li><code>[directive, value, arg]</code> - 上述内容，再加上一个 <code>string</code> 参数，比如：在 <code>v-on:click</code> 中的 <code>click</code>。</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> MyDirective <span class="token operator">=</span> <span class="token function">resolveDirective</span><span class="token punctuation">(</span><span class="token string">'MyDirective'</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> nodeWithDirectives <span class="token operator">=</span> <span class="token function">withDirectives</span><span class="token punctuation">(</span><span class="token function">h</span><span class="token punctuation">(</span><span class="token string">'div'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>
  <span class="token punctuation">[</span>MyDirective<span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token string">'click'</span><span class="token punctuation">]</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><ul><li><code>[directive, value, arg, modifiers]</code> - 上述内容，再加上定义任何修饰符的 <code>key: value</code> 键值对 <code>Object</code>。</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> MyDirective <span class="token operator">=</span> <span class="token function">resolveDirective</span><span class="token punctuation">(</span><span class="token string">'MyDirective'</span><span class="token punctuation">)</span>
<span class="token keyword">const</span> nodeWithDirectives <span class="token operator">=</span> <span class="token function">withDirectives</span><span class="token punctuation">(</span><span class="token function">h</span><span class="token punctuation">(</span><span class="token string">'div'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>
  <span class="token punctuation">[</span>MyDirective<span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token string">'click'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> prevent<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">]</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div></li></ul> <h2 id="createrenderer"><a href="#createrenderer" class="header-anchor">#</a> createRenderer</h2> <p>createRenderer 函数接受两个泛型参数：
<code>HostNode</code> 和 <code>HostElement</code>，对应于宿主环境中的 Node 和 Element 类型。</p> <p>例如，对于 runtime-dom，HostNode 将是 DOM <code>Node</code> 接口，HostElement 将是 DOM <code>Element</code> 接口。</p> <p>自定义渲染器可以传入特定于平台的类型，如下所示：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> createRenderer <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>
<span class="token keyword">const</span> <span class="token punctuation">{</span> render<span class="token punctuation">,</span> createApp <span class="token punctuation">}</span> <span class="token operator">=</span> createRenderer<span class="token operator">&lt;</span>Node<span class="token punctuation">,</span> Element<span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  patchProp<span class="token punctuation">,</span>
  <span class="token operator">...</span>nodeOps
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="参数-9"><a href="#参数-9" class="header-anchor">#</a> 参数</h3> <p>接受两个参数：<code>HostNode</code> 和 <code>HostElement</code>。</p> <h4 id="hostnode"><a href="#hostnode" class="header-anchor">#</a> HostNode</h4> <ul><li><p><strong>类型：</strong><code>Node</code></p></li> <li><p><strong>详细：</strong></p> <p>宿主环境中的节点。</p></li></ul> <h4 id="hostelement"><a href="#hostelement" class="header-anchor">#</a> HostElement</h4> <ul><li><p><strong>类型：</strong><code>Element</code></p></li> <li><p><strong>详细：</strong></p> <p>宿主环境中的元素。</p></li></ul> <h2 id="nexttick"><a href="#nexttick" class="header-anchor">#</a> nextTick</h2> <p>将回调推迟到下一个 DOM 更新周期之后执行。在更改了一些数据以等待 DOM 更新后立即使用它。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> createApp<span class="token punctuation">,</span> nextTick <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>

<span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token function">setup</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> message <span class="token operator">=</span> <span class="token function">ref</span><span class="token punctuation">(</span><span class="token string">'Hello!'</span><span class="token punctuation">)</span>
    <span class="token keyword">const</span> <span class="token function-variable function">changeMessage</span> <span class="token operator">=</span> <span class="token keyword">async</span> <span class="token parameter">newMessage</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
      message<span class="token punctuation">.</span>value <span class="token operator">=</span> newMessage
      <span class="token keyword">await</span> <span class="token function">nextTick</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
      console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'Now DOM is updated'</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><p><strong>参考</strong>：<a href="/api/instance-methods.html#nexttick"><code>$nextTick</code> 实例方法</a></p></div> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/api/application-api.html" class="prev">应用 API</a></span> <span class="next"><a href="/api/options-data.html">Data</a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.0a9bf1a0.js" defer></script><script src="/assets/js/9.f307b0a5.js" defer></script><script src="/assets/js/18.9c9769d1.js" defer></script><script src="/assets/js/10.523605bb.js" defer></script><script src="/assets/js/42.eb469d2e.js" defer></script>
  </body>
</html>
